﻿#include "stdafx.h"
#include "C_ConductiveLine.h"

#include "Source/SettingModule/S_SettingDataContainer.h"


/*
-----==========================================================-----
		类：		导线 数据类.h
		作者：		drill_up
		所属模块：	材料模块
		功能：		导线 的数据类对象。
-----==========================================================-----
*/

C_ConductiveLine::C_ConductiveLine() : C_UndoDataBase(){

	// > 属性
	this->name = "";				//名称
	
	// > 坐标
	this->x1 = 0;
	this->y1 = 0;
	this->z1 = 0;
	this->x2 = 0;
	this->y2 = 0;
	this->z2 = 0;

}
C_ConductiveLine::~C_ConductiveLine(){
}



/*-------------------------------------------------
		描述 - 获取属性描述
*/
QPair<QString, QString> C_ConductiveLine::getAttributesDesc() {
	QPair<QString, QString> context_pair;

	// > 获取长度
	C_SettingUnits unit = S_SettingDataContainer::getInstance()->getDataUnits();
	double len = qSqrt((this->x2 - this->x1) * (this->x2 - this->x1) + (this->y2 - this->y1) * (this->y2 - this->y1) + (this->z2 - this->z1) * (this->z2 - this->z1));

	context_pair.first.append(QObject::tr("Type"));
	context_pair.first.append("\n");
	context_pair.second.append("= ");
	context_pair.second.append(QObject::tr("ConductiveLine"));
	context_pair.second.append("\n");

	context_pair.first.append(QObject::tr("Length"));
	context_pair.first.append("\n");
	context_pair.second.append("= ");
	context_pair.second.append(QString::number(len));
	context_pair.second.append(unit.getCurrentString_dimensions());
	context_pair.second.append("\n");

	context_pair.first.append("P1");
	context_pair.first.append("\n");
	context_pair.second.append("= (");
	context_pair.second.append(QString::number(this->x1));
	context_pair.second.append(",");
	context_pair.second.append(QString::number(this->y1));
	context_pair.second.append(",");
	context_pair.second.append(QString::number(this->z1));
	context_pair.second.append(")");
	context_pair.second.append("\n");

	context_pair.first.append("P2");
	context_pair.first.append("\n");
	context_pair.second.append("= (");
	context_pair.second.append(QString::number(this->x2));
	context_pair.second.append(",");
	context_pair.second.append(QString::number(this->y2));
	context_pair.second.append(",");
	context_pair.second.append(QString::number(this->z2));
	context_pair.second.append(")");
	context_pair.second.append("\n");

	return context_pair;
}


/*-------------------------------------------------
		访问器 - 获取子类类名
*/
QString C_ConductiveLine::get__CLASS_NAME__(){
	return "C_ConductiveLine";
}
/*-------------------------------------------------
		访问器 - 获取子类类名（中文名）
*/
QString C_ConductiveLine::get__CLASS_NAME__Chinese(){
	return "导线";
}
/*-------------------------------------------------
		访问器 - 获取所有继承的类名
*/
QStringList C_ConductiveLine::get__CLASS_INHERITED_LIST__(){
	return C_UndoDataBase::get__CLASS_INHERITED_LIST__() << "C_ConductiveLine";
}
/*-------------------------------------------------
		访问器 - 是否继承了某类
*/
bool C_ConductiveLine::get__CLASS_IS_INSTANCE_OF__(QString class_name){
	return this->get__CLASS_INHERITED_LIST__().contains(class_name);
}
/*-------------------------------------------------
		访问器 - 原型复制对象
*/
C_ConductiveLine C_ConductiveLine::clone(){
	return C_ConductiveLine(*this);
}
QSharedPointer<C_ConductiveLine> C_ConductiveLine::clonePtr(){
	return QSharedPointer<C_ConductiveLine>(new C_ConductiveLine(*this));
}
C_UndoDataBasePtr C_ConductiveLine::cloneParentPtr(){
	return this->clonePtr();
}

/*-------------------------------------------------
		复制对象
*/
void C_ConductiveLine::copyFrom(C_ConductiveLine* a){

	// > 属性
	this->name = a->name;

	// > 坐标
	this->x1 = a->x1;
	this->y1 = a->y1;
	this->z1 = a->z1;
	this->x2 = a->x2;
	this->y2 = a->y2;
	this->z2 = a->z2;
}
/*-------------------------------------------------
		运算符重载
*/
const bool C_ConductiveLine::operator== (const C_ConductiveLine& a)const {
	return C_UndoDataBase::operator==(a);
}
/*-------------------------------------------------
		空判断
*/
bool C_ConductiveLine::isNull(){
	return C_UndoDataBase::isNull();
}

/*-------------------------------------------------
		实体类 -> QJsonObject
*/
QJsonObject C_ConductiveLine::getJsonObject_undoChildData(){
	QJsonObject obj;

	// > 属性
	obj.insert("name", this->name);

	// > 坐标
	obj.insert("x1", this->x1);
	obj.insert("y1", this->y1);
	obj.insert("z1", this->z1);
	obj.insert("x2", this->x2);
	obj.insert("y2", this->y2);
	obj.insert("z2", this->z2);

	return obj;
}
/*-------------------------------------------------
		QJsonObject -> 实体类
*/
void C_ConductiveLine::setJsonObject_undoChildData(QJsonObject obj){

	// > 属性
	this->name = obj.value("name").toString();

	// > 参数
	this->x1 = obj.value("x1").toDouble();
	this->y1 = obj.value("y1").toDouble();
	this->z1 = obj.value("z1").toDouble();
	this->x2 = obj.value("x2").toDouble();
	this->y2 = obj.value("y2").toDouble();
	this->z2 = obj.value("z2").toDouble();

}
